#ifndef _CONFIG_DATA_MANAGE_H
#define _CONFIG_DATA_MANAGE_H
#include <map>
#include "configData.h"

#define STC_CONFIG_MAP(ClassType) \
    ((ClassType*)configDataManage::getInstance()->GetConfigBase(ClassType::GetName()))->GetMap()

#define STC_CONFIG_BY_ID(ClassType,key) \
    ((ClassType*)configDataManage::getInstance()->GetConfigBase(ClassType::GetName()))->GetById(key)

class configDataManage
{
public:
    static configDataManage* getInstance()
    {
        static configDataManage cfg;
        return &cfg;
    }
    configDataBase* GetConfigBase(std::string name)
    {
        if(m_mapConfig.find(name) == m_mapConfig.end())
        {
            return nullptr;
        }
        return m_mapConfig[name];
    }
    bool LoadConfig(configDataBase* config,const std::string name,const std::string& filepath)
    {   
        if(m_mapConfig.find(name) == m_mapConfig.end())
        {
            return false;
        }
        if(!config->Load(filepath))
        {
            return false;
        }
        m_mapConfig[name] = config;
        return true;
    }
protected:
    configDataManage(){}
    ~configDataManage(){}
private:
    std::map<std::string,configDataBase*> m_mapConfig;
};

#endif